package com.cqc.jdk8.Jutil.function;

import org.junit.Test;

import java.util.Objects;
import java.util.function.Predicate;

/**
 * @author cui
 * @date 2024/6/22 10:06
 * @description
 **/
public class PredicateTest {

    @Test
    public void f1() {
        //Predicate<T>  T是参数类型
        Predicate<String> p1 = (s) -> s.length() > 0;
        boolean r1 = p1.test("123");
        //negate()取反
        boolean r2 = p1.negate().test("123");
        System.out.println(r1 + "---" + r2);
        //相当于
        Predicate<String> p = new Predicate<String>() {
            @Override
            public boolean test(String s) {
                boolean flag = s.length() > 0;
                return flag;
            }
        };

        Predicate<Boolean> p3 = Objects::isNull;
        Predicate<Integer> p4 = Objects::nonNull;
        boolean r3 = p3.test(true);
        boolean r4 = p4.test(8);
        System.out.println(r3 + "---" + r4);


        Predicate<String> p5 = String::isEmpty;
        Predicate<String> p6 = p5.negate();
        boolean r5 = p5.test("");
        boolean r6 = p6.test("aaa");
        System.out.println(r5 + "---" + r6);

        //报错 Non-static method cannot be referenced from a static context
//        Predicate<String> p7=String::startsWith;

    }
}
